package com.share.demo.jvm;


import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;

/**
 * -Xmx20M -XX:MaxDirectMemorySize=10M 本机内存直接溢出
 *
 * author:caifan
 * date:2019/10/4
 */
public class DirectMemoryOOM {
    private static final int _MB = 1024 * 1024;

    public static void main(String[] args) throws Exception {
//        Field field = MethodHandles.Lookup.class.getDeclaredFields()[0];
////        Field field = Unsafe.class.getDeclaredFields()[0];//jdk 1.8及之前
//        field.setAccessible(true);
////        Unsafe unsafe = (Unsafe) field.get(null);
//        MethodHandles.Lookup unsafe = (MethodHandles.Lookup) field.get(null);
//        while (true) {
////            unsafe.allocateMemory(_MB);
//            unsafe.dropLookupMode(_MB);
//        /}
    }
}
